<?php
include 'config.php';
	$con = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME) or die ("Could not execute query");
	$query = "SELECT * FROM d3 WHERE userid = 1";
	$result = mysqli_query($con,$query) or die ("Could not SELECT lexid, context1 FROM d3");
	$num =  mysqli_num_rows($result);
	$data = array();
        for ($x = 0; $x < $num ; $x++) {
        $data[] = mysqli_fetch_assoc($result);
    
  //echo json_encode($data);   
 echo ' {'; 
  echo ' 	"name": "example",'; 
  echo ' 	"children": ['; 	
	while ($num = mysqli_fetch_assoc($result))
    {
    $source  = json_encode($num['source']);
    $id = json_encode($num['id']);
	$type = json_encode($num['type']);
	$context= json_encode($num['context']);
	$title = json_encode($num['title']);


foreach ($num as $num ) {
	

	//echo json_encode($data);   

  // echo ' { "name":' . $id .  ',';
  // echo ' "children": [';
	// echo ' { '; 
		  // echo '  "name":'  . $context . ',';
		  // echo ' "children": [';
		 // echo ' { '; 
			  // echo ' "name":"node1",
			  // "title":3353' ;
			  // echo '},'; 
			  // echo ' { '; 
			  // echo ' "name":"node2",
			  // "title":3353' ;
			  // echo '}';    
		  // echo ']';
		// echo ' } ';   
	 // echo ']';
	 // echo ' } ';   
	
 
  echo ' {'; 
  echo '"name": "group1",'; 
  echo ' "children": ['; 
  echo ' {'; 
  echo ' "name": "node1",'; 
  echo ' "size": 1000'; 
  echo ' }, {'; 
  echo ' "name": "node2",'; 
  echo ' "size": 2000'; 
  echo ' }, {'; 
  echo ' "name": "node3",'; 
  echo ' "size": 3000'; 
  echo ' }'; 
  echo ' ]'; 
  echo ' }, {'; 
  echo ' "name": "node4",'; 
  echo ' "size": 4000'; 
  echo ' }, {'; 
  echo ' "name": "node5",'; 
  echo ' "size": 5000'; 
  echo ' }'; 
  echo ' ]'; 
  echo ' }'; 
}	
	};
  

		};
		  echo ' 	]'; 
  echo ' }  '; 
header("content-type:application/json");
?>



